#include<iostream>
using namespace std;

int mod_exp(int a,int b,int m)
{
	int t=a%m;
	int res=1;
	while(b)
	{
		if(b&1)
		{
			res=res*t%m;
		}
		b=b>>1;
		t=t*t%m;
	}
	return res;
}

int main()
{
	int a,b;
	while(cin>>a>>b&&a+b)
	{
		cout<<mod_exp(a,b,1000)<<endl;
	}
	return 0;
}
